package com.xtedu.examproject.service;

import com.xtedu.examproject.dao.base.CourseDao;
import com.xtedu.examproject.dao.impl.CourseDaoImpl;
import com.xtedu.examproject.entity.Course;
import com.xtedu.examproject.entity.Teacher;
import com.xtedu.examproject.util.PageHelper;

import java.util.List;

public class CourseService {
    private CourseDao courseDao;

    public CourseService(){
        courseDao = new CourseDaoImpl();
    }

    public int insertCourse(Course course) throws Exception {
        return courseDao.insert(course);
    }

    public Course findById(int id) throws Exception {
        return courseDao.findById(id);
    }
    //删除课程
    public boolean deleteCourseById(int courseId) throws Exception {
        return courseDao.deleteCourseById(courseId);
    }
    public PageHelper<Course> findPageSelectByRoleId(int pageIndex, int pageSize, int roleId) throws Exception {
        return courseDao.findPageSelectByRoleId(pageIndex, pageSize, roleId);
    }
    public PageHelper<Course> findPageSelectByCourseName(String courseName, int pageIndex, int pageSize) throws Exception {
        return courseDao.findPageSelectByCourseName(courseName, pageIndex, pageSize);
    }
    public PageHelper<Course> findPageSelectBySubjectName(String subjectName, int pageIndex, int pageSize) throws Exception {
        return courseDao.findPageSelectBySubjectName(subjectName, pageIndex, pageSize);
    }
    public PageHelper<Course> findCoursesByCourseAndSubjectName(String courseName,String subjectName, int pageIndex, int pageSize) throws Exception {
        return courseDao.findCoursesByCourseAndSubjectName(courseName,subjectName, pageIndex, pageSize);
    }

    public PageHelper<Course> findAll(int pageIndex, int pageSize) throws Exception {
        return courseDao.findAll(pageIndex, pageSize);
    }

    public boolean updateCourses(Course course) throws Exception {
        return courseDao.updateCourses(course);
    }

    public List<Course> findSelectBySubjectName(String subjectName) throws Exception {
        return courseDao.findSelectBySubjectName(subjectName);
    }

    public boolean saveCourseBySort(List<Course> courses) throws Exception {
        return courseDao.saveCourseBySort(courses);
    }

    public List< Course> findAllCourse() throws Exception {
        return courseDao.findAll();
    }
    public List<Teacher> findCourseByTeacher(int courseId) throws Exception {
        return courseDao.findCourseByTeacher(courseId);
    }

    public List<Teacher> findAllTeachers() throws Exception {
        return courseDao.findAllTeachers();
    }

    public boolean setCourseTeacher(int courseId, int teacherId){
        return courseDao.setCourseTeacher(courseId, teacherId);
    }

    public boolean removeTeacherFromCourse(int teacherId, int courseId){
        return courseDao.removeTeacherFromCourse(teacherId, courseId);
    }

    public List<Course> findBySubjectId(int subjectId) throws Exception {
        return courseDao.findBySubjectId(subjectId);
    }

    public int findCourseIdByStudentId(int studentId) throws Exception {
    	return courseDao.findCourseIdByStudentId(studentId);
    }

    public List<Course> findAllCourseIdAndName() throws Exception {
    	return courseDao.findAllCourseIdAndName();
    }
}
